package com.gome.ss.flowcrawl.extractor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.mongodb.DBObject;

public class FlowCrawlExtractorConfig {
	
	private String name;
	private String stepID;
	private boolean dataPushToMQ = false;
	private String dataMQName = "";
	private String endCallbackLink = "";
	private Map<String, FlowCrawlExtractorConfigField> extractFiled = new HashMap<String, FlowCrawlExtractorConfigField>();
	private List<String> facetKeys = new ArrayList<String>();
	
	public FlowCrawlExtractorConfig(DBObject obj) {
		name = (String) obj.get("name");
		stepID = (String) obj.get("stepID");
		
		if (obj.get("dataPushToMQ") != null && obj.get("dataPushToMQ") != null) {
			dataPushToMQ = (Boolean) obj.get("dataPushToMQ");
			if (dataPushToMQ) {
				dataMQName = (String) obj.get("dataMQName");
				if (dataMQName.equals(""))
					dataPushToMQ = false;
			}
		}
		
		if (obj.get("endCallbackLink") != null)
			endCallbackLink = (String) obj.get("endCallbackLink");
		
		List<DBObject> fieldObjs = (List<DBObject>) obj.get("fields");
		for (DBObject fobj : fieldObjs) {
			FlowCrawlExtractorConfigField field = new FlowCrawlExtractorConfigField(fobj);
			extractFiled.put(field.getKey(), field);
			if (field.isIndex())
				facetKeys.add(field.getKey());
		}
	}

	public String getName() {
		return name;
	}

	public String getStepID() {
		return stepID;
	}

	public boolean isDataPushToMQ() {
		return dataPushToMQ;
	}

	public String getEndCallbackLink() {
		return endCallbackLink;
	}

	public String getDataMQName() {
		return dataMQName;
	}

	public Map<String, FlowCrawlExtractorConfigField> getExtractFileds() {
		return extractFiled;
	}
	
	public FlowCrawlExtractorConfigField getExtractFiled(String key) {
		if (extractFiled.containsKey(key))
			return extractFiled.get(key);
		return null;
	}

	public List<String> getFacetKeys() {
		return facetKeys;
	}
}
